home *** CD-ROM | disk | FTP | other *** search
- { listing 1 - corrected Exec for Turbo Pascal }
-
- {--------------------------- Exec ----------------------------}
- { execute 'Command' as if it was typed at the A> prompt }
- { requires Getenvironment function from Micro C. 32 }
- {-------------------------------------------------------------}
- FUNCTION Exec (Command : string128) : INTEGER;
-
- CONST
- SSSave : INTEGER = 0;
- SPSave : INTEGER = 0;
- RetAX : INTEGER = 0;
- RetFlags : INTEGER = 0;
-
- TYPE
- ExecPacketRec = RECORD
- EnvironmentSeg : INTEGER;
- CommandPtr,
- FCB1,
- FCB2 : ^CHAR;
- end; { ExecPacketRec }
-
- VAR ComFile : String20;
- ExecPack : ExecPacketRec;
-
- begin
- ComFile := GetEnvironment('COMSPEC')+chr(0);{ execute command.com }
- IF (length(command) > 0) THEN { sending it this line }
- Insert ('/c ',Command,1); { 'c' switch means 'do this' }
- command[length(command)+1] := ^M;
-
- ExecPack.EnvironmentSeg := $0000; { use parent's environment }
- ExecPack.CommandPtr := Ptr(seg(Command),ofs(Command));
- ExecPack.FCB1 := Ptr(0,0);
- ExecPack.FCB2 := Ptr(0,0);
-
- { START OF MODIFIED AREA }
- inline($06/$1E/$55/$9C/ { push es, ds, bp, flags }
- $8C/$D0/$8E/$D8/ { mov ax,ss mov ds,ax (seg(ComFile)) }
- $BA/ComFile/ { mov dx,offset ComFile[0] }
- $01/$EA/$42/ { add dx,bp inc dx }
- $8E/$C0/ { mov es,ax (seg(ExecPack)) }
- $BB/ExecPack/ { mov bx,offset ExecPack }
- $01/$EB/ { add bx,bp }
- $B8/$00/$4B/ { mov ax,4B00h }
- $2E/$8C/$16/SSSave/ { mov cs:[SSSave],ss <<-}
- $2E/$89/$26/SPSave/ { mov cs:[SPSave],sp <<-}
- $CD/$21/ { int 21h }
- $2E/$8E/$16/SSSave/ { mov ss,cs:[SSSave] <<-}
- $2E/$8B/$26/SPSave/ { mov sp,cs:[SPSave] <<-}
- $2E/$A3/RetAX/ { mov cs:[RetAX],ax }
- $9C/$58/ { pushf pop ax }
- $2E/$A3/RetFlags/ { mov cs:[RetFlags],ax }
- $9D/$5D/$1F/$07); { pop flags, bp, ds, es }
-
- IF ((RetFlags and CARRY) = 0) THEN
- Exec := 0
- ELSE
- Exec := RetAX;
- { END OF MODIFIED AREA }
- end; { Exec }
-